package com.gavin.lingxi.rtclib;

/**
 * Peer connection parameters.
 */
public class PeerConnectionParameters {

    public final boolean videoCallEnabled;
    public final boolean audioCallEnabled;
    public final boolean loopback;
    public final boolean tracing;
    public final int videoWidth;
    public final int videoHeight;
    public final int videoFps;
    public final int videoMaxBitrate;
    public final String videoCodec;
    public final boolean videoCodecHwAcceleration;
    public final boolean videoFlexfecEnabled;
    public final int audioStartBitrate;
    public final String audioCodec;
    public final boolean noAudioProcessing;
    public final boolean aecDump;
    public final boolean saveInputAudioToFile;
    public final boolean useOpenSLES;
    public final boolean disableBuiltInAEC;
    public final boolean disableBuiltInAGC;
    public final boolean disableBuiltInNS;
    public final boolean disableWebRtcAGCAndHPF;
    public final boolean enableRtcEventLog;
    public final boolean useLegacyAudioDevice;
    public final PeerConnectionClient.DataChannelParameters dataChannelParameters;
    public boolean enableStats;

    private PeerConnectionParameters(boolean videoCallEnabled, boolean audioCallEnabled, boolean loopback, boolean tracing,
                                    int videoWidth, int videoHeight, int videoFps, int videoMaxBitrate, String videoCodec,
                                    boolean videoCodecHwAcceleration, boolean videoFlexfecEnabled, int audioStartBitrate,
                                    String audioCodec, boolean noAudioProcessing, boolean aecDump, boolean saveInputAudioToFile,
                                    boolean useOpenSLES, boolean disableBuiltInAEC, boolean disableBuiltInAGC,
                                    boolean disableBuiltInNS, boolean disableWebRtcAGCAndHPF, boolean enableRtcEventLog,
                                    boolean useLegacyAudioDevice, PeerConnectionClient.DataChannelParameters dataChannelParameters,
                                    boolean enableStats) {
        this.videoCallEnabled = videoCallEnabled;
        this.audioCallEnabled = audioCallEnabled;
        this.loopback = loopback;
        this.tracing = tracing;
        this.videoWidth = videoWidth;
        this.videoHeight = videoHeight;
        this.videoFps = videoFps;
        this.videoMaxBitrate = videoMaxBitrate;
        this.videoCodec = videoCodec;
        this.videoFlexfecEnabled = videoFlexfecEnabled;
        this.videoCodecHwAcceleration = videoCodecHwAcceleration;
        this.audioStartBitrate = audioStartBitrate;
        this.audioCodec = audioCodec;
        this.noAudioProcessing = noAudioProcessing;
        this.aecDump = aecDump;
        this.saveInputAudioToFile = saveInputAudioToFile;
        this.useOpenSLES = useOpenSLES;
        this.disableBuiltInAEC = disableBuiltInAEC;
        this.disableBuiltInAGC = disableBuiltInAGC;
        this.disableBuiltInNS = disableBuiltInNS;
        this.disableWebRtcAGCAndHPF = disableWebRtcAGCAndHPF;
        this.enableRtcEventLog = enableRtcEventLog;
        this.useLegacyAudioDevice = useLegacyAudioDevice;
        this.dataChannelParameters = dataChannelParameters;
        this.enableStats = enableStats;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        boolean video_call = true;
        boolean audio_call = true;
        boolean loopback = false;
        boolean tracing = false;
        int videoWidth = 640;
        int videoHeight = 360;
        int videoFps = 10;
        int videoMaxBitrate = 0; //kbps
        String video_codec = "VP9";
        boolean hwcodec_enabled = true;
        boolean flexfec_enabled = true;
        int audio_bitrate = 0;
        String audio_codec = "ISAC";
        boolean noaudio_processing_enabled = false;
        boolean aecdump_enabled = false;
        boolean sava_input_audio_to_file_anabled = false;
        boolean opensles_enabled = false;
        boolean disable_built_in_aec = false;
        boolean disable_built_in_agc = false;
        boolean disable_built_in_ns = false;
        //        boolean enable_level_control = false;
        boolean disable_webrtc_agc_and_hpf = false;
        boolean enable_rtceventlog = true;
        boolean use_legacy_audio_device = false;
        public boolean enableStats = false;

        private Builder(){

        }

        public Builder setVideoCall(boolean videoCall) {
            this.video_call = videoCall;
            return this;
        }

        public Builder setAudioCall(boolean audioCall) {
            this.audio_call = audioCall;
            return this;
        }

        public Builder setLoopback(boolean loopback) {
            this.loopback = loopback;
            return this;
        }

        public Builder setTracing(boolean tracing) {
            this.tracing = tracing;
            return this;
        }

        public Builder setVideoWidth(int videoWidth) {
            this.videoWidth = videoWidth;
            return this;
        }

        public Builder setVideoHeight(int videoHeight) {
            this.videoHeight = videoHeight;
            return this;
        }

        public Builder setVideoFps(int videoFps) {
            this.videoFps = videoFps;
            return this;
        }

        public Builder setVideoMaxBitrate(int videoBitrate) {
            this.videoMaxBitrate = videoBitrate;
            return this;
        }

        public Builder setVideoCodec(String videoCodec) {
            this.video_codec = videoCodec;
            return this;
        }

        public Builder setHwcodecEnabled(boolean hwcodecEnabled) {
            this.hwcodec_enabled = hwcodecEnabled;
            return this;
        }

        public Builder setFlexfecEnabled(boolean flexfecEnabled) {
            this.flexfec_enabled = flexfecEnabled;
            return this;
        }

        public Builder setAudioBitrate(int audioBitrate) {
            this.audio_bitrate = audioBitrate;
            return this;
        }

        public Builder setAudioCodec(String audioCodec) {
            this.audio_codec = audioCodec;
            return this;
        }

        public Builder setNoaudioProcessingEnabled(boolean noaudioProcessingEnabled) {
            this.noaudio_processing_enabled = noaudioProcessingEnabled;
            return this;
        }

        public Builder setAecdumpEnabled(boolean aecdumpEnabled) {
            this.aecdump_enabled = aecdumpEnabled;
            return this;
        }

        public Builder setSavaInputAudioToFileEnabled(boolean savaInputAudioToFileEnabled) {
            this.sava_input_audio_to_file_anabled = savaInputAudioToFileEnabled;
            return this;
        }

        public Builder setOpenslesEnabled(boolean openslesEnabled) {
            this.opensles_enabled = openslesEnabled;
            return this;
        }

        public Builder setDisableBuiltInAec(boolean disable_built_in_aec) {
            this.disable_built_in_aec = disable_built_in_aec;
            return this;
        }

        public Builder setDisableBuiltInAgc(boolean disable_built_in_agc) {
            this.disable_built_in_agc = disable_built_in_agc;
            return this;
        }

        public Builder setDisableBuiltInNs(boolean disable_built_in_ns) {
            this.disable_built_in_ns = disable_built_in_ns;
            return this;
        }

        public Builder setDisableWebrtcAgcAndHpf(boolean disableWebrtcagcAndpf) {
            this.disable_webrtc_agc_and_hpf = disableWebrtcagcAndpf;
            return this;
        }

        public Builder setEnableRtceventlog(boolean enableRtceventlog) {
            this.enable_rtceventlog = enableRtceventlog;
            return this;
        }

        public Builder setUseLegacyAudioDevice(boolean useLegacyAudioDevice) {
            this.use_legacy_audio_device = useLegacyAudioDevice;
            return this;
        }

        public void enableStats(boolean enableStats){
            this.enableStats = enableStats;
        }

        public PeerConnectionParameters createPeerConnectionParameters() {
            PeerConnectionClient.DataChannelParameters dataChannelParameters = null;
            dataChannelParameters = new PeerConnectionClient.DataChannelParameters(true, -1, -1, "", false, -1);

            PeerConnectionParameters peerConnectionParameters =
                    new PeerConnectionParameters(video_call, audio_call, loopback, tracing,
                            videoWidth, videoHeight, videoFps, videoMaxBitrate, video_codec,
                            hwcodec_enabled, flexfec_enabled, audio_bitrate,
                            audio_codec, noaudio_processing_enabled, aecdump_enabled, sava_input_audio_to_file_anabled, opensles_enabled,
                            disable_built_in_aec, disable_built_in_agc, disable_built_in_ns,
                            disable_webrtc_agc_and_hpf, enable_rtceventlog, use_legacy_audio_device, dataChannelParameters, enableStats);
            return peerConnectionParameters;
        }
    }
}
